package com.alpesressources.comexpert.util;

import java.lang.reflect.Type;

import com.alpesressources.comexpert.bo.IObject;
import com.alpesressources.comexpert.bo.adapter.RequestDeserializer;
import com.alpesressources.comexpert.bo.request.Request;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class MyJsonDeserializer {
	private Gson gson;

	public MyJsonDeserializer(Class<?> classToDeserialize) {
		RequestDeserializer requestDeserializer = new RequestDeserializer(
				classToDeserialize, this);

		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.disableHtmlEscaping();
		gsonBuilder.registerTypeAdapter(Request.class, requestDeserializer);
		gson = gsonBuilder.serializeNulls().create();
	}

	public Request deserializeRequest(String s) {
		return gson.fromJson(s, Request.class);
	}

	public IObject deserializeObject(String s, Type type) {
		return gson.fromJson(s, type);
	}
}
